package com.chong.activiti.service.impl;

import com.chong.activiti.model.User;
import com.chong.activiti.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author chong
 * @create 2020/6/4
 * Desc: 用户信息
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    JdbcTemplate jdbcTemplate;
    /**
     * 根据用户id获取对象
     * @param id
     * @return
     */
    @Override
    public User getOneById(Long id) {
        String sql ="select userName,id from user where ifDelete=0 and id=?";
        return jdbcTemplate.queryForObject(sql, new Object[]{id}, new RowMapper<User>() {
            @Override
            public User mapRow(ResultSet rs, int rowNum) throws SQLException {
                User user = new User();
                user.setId(id);
                user.setUserName(rs.getString("userName"));
                return user;
            }
        });
    }
}
